package com.aios.action.settings.controller;

import java.util.Locale;

import org.apache.log4j.Logger;

import com.aios.service.impl.ControllerServiceImpl;
import com.aios.service.impl.SwitchServiceImpl;

public class ControllerViewAction extends AbstractControllerAction {

	private static final long serialVersionUID = 1L;
	private static Logger logger = Logger.getLogger(ControllerServiceImpl.class);
	private String direction,zoomMode;

	
	public String execute() {
	
		try {
			populateCameraType(Locale.JAPAN);
			this.controller = controllerService.findById(id);
			
			if(actionMessage != null && !(actionMessage.equals(""))) {
				addActionMessage(actionMessage);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			return INPUT;
		}

		return SUCCESS;
	}
	public String cameraRotate() {
		try {
			if(id != null && direction != null) {
				controllerService.changeCameraDirection(id,Integer.parseInt(direction));
			} else {
				logger.error("invalid access to controller");
			}
			
		} catch(Exception e) {
			logger.error(e.toString());
		}
		
		return SUCCESS;
	}
	
	public String cameraZoom() {
		try {
			if(id != null && zoomMode != null) {
				controllerService.changeCameraZoom(id,zoomMode);
			} else {
				logger.error("invalid access to controller");
			}
			
		} catch(Exception e) {
			logger.error(e.toString());
		}
		
		return SUCCESS;
	}

	public String viewControllerStream() {
		return this.execute();
	}
	public String getDirection() {
		return direction;
	}
	public void setDirection(String direction) {
		this.direction = direction;
	}
	public String getZoomMode() {
		return zoomMode;
	}
	public void setZoomMode(String zoomMode) {
		this.zoomMode = zoomMode;
	}
}
